// 菜单状态
export type showMenu = "opened" | "closed";

/**
 * 系统State
 */
export interface AppState {
  //菜单状态
  sidebarMenu: showMenu;
  //移动端状态
  mobileMenu: showMenu;
  //顶部菜单选择ID
  headerMenuSelectedKey: number;
  //侧边菜单打开项
  sidebarMenuOpenKeys: string[];
  //侧边菜单选中项
  sidebarMenuSelectedKeys: string[];
}

export const useAppStore = defineStore("appStore", {
  state: (): AppState => ({
    sidebarMenu: "opened",
    mobileMenu: "closed",
    headerMenuSelectedKey: 1,
    sidebarMenuOpenKeys: ["11", "12"],
    sidebarMenuSelectedKeys: ["111"]
  }),
  actions: {
    setSidebarMenu(sidebarMenu: showMenu) {
      this.sidebarMenu = sidebarMenu;
    },
    setMobileMenu(mobileMenu: showMenu) {
      this.mobileMenu = mobileMenu;
    },
    setHeaderMenuSelectedKey(key: number) {
      this.headerMenuSelectedKey = key;
    },
    setSidebarMenuOpenKeys(keys: string[]) {
      this.sidebarMenuOpenKeys = keys;
    },
    setSidebarMenuSelectedKeys(keys: string[]) {
      this.sidebarMenuSelectedKeys = keys;
    }
  },
  persist: {
    enabled: true,
    strategies: [
      { storage: localStorage, paths: ["headerMenuSelectedKey", "sidebarMenuOpenKeys", "sidebarMenuSelectedKeys"] }
    ]
  }
});
